class Solution {
public:
    bool canJump(vector<int>& nums) {
        int size = nums.size();
        int i = 0;
        while (i < size - 1)
        {
            int cur = nums[i];
            // cout << i << ' ' << cur << endl;
            if (i + cur >= size - 1) return true;
            if (cur == 0) return false;

            int next = i + 1;
            for (int j = next; j < size - 1 && j <= i + cur; j++)
            {
                if (next + nums[next] <= j + nums[j])
                    next = j;
            }
            i = next;
        }
        // cout << i << endl;
        return i == size - 1;
    }
};